-- 箱子物品排序
function XS_ChestItemsSort(container)
    local prefabs = {}
    local slots = container_inst.components.container.slots
    if GetTableSize(slots) > 1 then
        for _, slot_inst in pairs(slots) do
            if slot_inst and slot_inst:IsValid() then
                if not HasTableKey(prefabs, slot_inst.prefab) then
                    prefabs[slot_inst.prefab] = {}
                end
                table.insert(prefabs[slot_inst.prefab], slot_inst)
                slot_inst.components.inventoryitem:RemoveFromOwner(true)             -- 从原库存内摘出
            end
        end
        local prefabs_keys = GetTableKeys(prefabs)
        if #prefabs_keys > 0 then
            pass2 = true
            table.sort(prefabs_keys)
            for _, prefab in pairs(prefabs_keys) do
                for _, prefab_inst in pairs(prefabs[prefab]) do
                    container_inst.components.container:GiveItem(prefab_inst)             -- 放入箱子
                end
            end
        end
    end
end
